﻿using ITSM.Model;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITSM.Service
{
    public class EntityService : BaseDB, IEntity
    {
        private readonly ILogger<BaseDB> _logger;

        public EntityService(ILogger<EntityService> logger)
        {
            _logger = logger;
        }

        public bool CreateEntity(string entityName, string filePath)
        {
            try
            {
                db.DbFirst.IsCreateAttribute().Where(entityName).CreateClassFile(filePath);
                _logger.LogInformation("表名：{entityName}，文件地址：{filePath}，实体类创建成功", entityName, filePath);
                db.Close();
                return true;
            }
            catch (Exception e)
            {
                _logger.LogError("实体类创建失败：{e}",e.Message);
                return false;
            }
        }
    }
}
